using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using Utility;
using BUS;
public partial class Doanhnghiep_ThemSP_DN : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDropDownList();
        }
    }

    private void LoadDropDownList()
    {
        tbDanhMucSanPhamCollection dmCollection = tbDanhMucSanPhamBUS.GetAll();
        ddl_dm.DataTextField = tbDanhMucSanPhamColumns.tendanhmuc.ToString();
        ddl_dm.DataValueField = tbDanhMucSanPhamColumns.madanhmuc.ToString();
        ddl_dm.DataSource = dmCollection;
        ddl_dm.DataBind();

        
    }

    protected void btn_Them_Click(object sender, EventArgs e)
    {

            int id = int.Parse(Request.QueryString["id"].ToString());
            tbSanPham sanpham = new tbSanPham();
            sanpham.tinvantat = TextBox1.Text;
            sanpham.tensp = txt_TenSP.Text;
            sanpham.danhmuc = int.Parse(ddl_dm.SelectedValue);
            sanpham.doanhnghiep = id;
            sanpham.giagoc = float.Parse(txt_giagoc.Text);
            sanpham.giaban = float.Parse(txt_giaban.Text);
            sanpham.soluongban = float.Parse(txt_soluongban.Text);
            sanpham.soluongtoida = float.Parse(txt_soluongtoida.Text);
            sanpham.damua = 0;
            sanpham.chietkhau = float.Parse(txt_chietkhau.Text);
            sanpham.ngaysudung =DateTime .Parse (txt_ngaysudung.Text);
            sanpham.ngayhethan =DateTime .Parse (txt_ngayhethan.Text);
            sanpham.tinhtrang = 12;  //12 la ma cua SP dang cho
            sanpham.mota = ftb_mota.Text;
            sanpham.quydinh = ftb_quydinh.Text;
            if (fu_HinhMinhHoa.HasFile)
            {
                string filename = DateTime.Now.Ticks.ToString() + "_" + fu_HinhMinhHoa.FileName;
                fu_HinhMinhHoa.SaveAs(Server.MapPath("~/Photos/" + filename));
                System.Drawing.Image img = System.Drawing.Image.FromFile(
                    Server.MapPath("~/Photos/" + filename));
                ImageUtility.MakeThumbnailPhoto(
                    img, 100, 100, Server.MapPath("~/Photos/Thumb/"), filename);
                sanpham.hinhchinh = filename;
            }
            else
            {
                sanpham.hinhchinh = "no_images.jpg";
            }
            tbSanPhamBUS.Insert(sanpham);
            Response.Redirect("~/DoanhNghiep/SanPham_DN.aspx?id="+sanpham .doanhnghiep .ToString ());
        }
        //"~/DoanhNghiep/SanPham_DN.aspx?id=" + dn.madn.ToString();
        
}
